#ifndef __SOFT_IIC_DRV_H__
#define __SOFT_IIC_DRV_H__

#include "n32l40x.h"
#include "my_gpio.h"

#include "main.h"
#include <stdio.h>
#include <stdint.h>

//---V1.1硬件接线方法 PA10 --SDA, PA9 --SCL
#define SOFT_SDA_PORT   GPIOA
#define SOFT_SDA_PIN    GPIO_PIN_10

#define I2C_SDA_L()     set_pin_low(SOFT_SDA_PORT, SOFT_SDA_PIN)    
#define I2C_SDA_H()     set_pin_high(SOFT_SDA_PORT, SOFT_SDA_PIN) 

#define I2C_SDA_Set()   (I2C_SDA_H())
#define I2C_SDA_Clr()   (I2C_SDA_L())

// 读取
#define IS_SDA_H()     (Bit_SET == GPIO_ReadInputDataBit(SOFT_SDA_PORT, SOFT_SDA_PIN)) 

//   #include "soft_iic_drv.h"

#define SOFT_SCL_PORT   GPIOA
#define SOFT_SCL_PIN    GPIO_PIN_9

#define I2C_SCL_L()     set_pin_low(SOFT_SCL_PORT, SOFT_SCL_PIN)    
#define I2C_SCL_H()     set_pin_high(SOFT_SCL_PORT, SOFT_SCL_PIN) 

#define I2C_SCL_Set()   (I2C_SCL_H())
#define I2C_SCL_Clr()   (I2C_SCL_L())

void Start(void);
void SendData(u8 dat);
void RecvACK(void);
char RecvData(u8 SF_Ack);
void SendACK(void);
void SendNAK(void);
void Stop(void);

void soft_iic_init(void);

#endif
